<%--
  products.jsp
  作用：管理员后台的商品管理页面，展示所有商品列表，并提供删除商品的功能。
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>商品管理 - 管理后台</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/layout.css">
    <script>
        function confirmDelete(productId) {
            if (confirm('您确定要删除这个商品吗？此操作不可撤销。')) {
                window.location.href = '${pageContext.request.contextPath}/admin/deleteProduct?productId=' + productId;
            }
        }
    </script>
</head>
<body>
<div class="main-container">
    <jsp:include page="/WEB-INF/parts/sidebar.jsp" />

    <main class="content-area">
        <jsp:include page="/WEB-INF/parts/header.jsp" />

        <div class="page-title">
            <h2>商品管理</h2>
        </div>

        <c:if test="${not empty message}">
            <p class="success-message">${message}</p>
        </c:if>

        <div class="admin-table-container">
            <table class="admin-table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>商品图片</th>
                    <th>商品名称</th>
                    <th>发布者</th>
                    <th>价格</th>
                    <th>状态</th>
                    <th>创建时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach var="product" items="${products}">
                    <tr>
                        <td>${product.id}</td>
                        <td><img src="${pageContext.request.contextPath}/uploads/product_images/${product.imageUrl}" alt="${product.name}" width="60"></td>
                        <td><c:out value="${product.name}" /></td>
                        <td><c:out value="${product.seller.username}" /></td>
                        <td><fmt:formatNumber value="${product.price}" type="currency" currencySymbol="¥" /></td>
                        <td>
                            <c:choose>
                                <c:when test="${product.status == 'on_shelf'}"><span class="status-active">在售</span></c:when>
                                <c:when test="${product.status == 'sold'}"><span class="status-banned">已售</span></c:when>
                                <c:otherwise><span class="status-other"><c:out value="${product.status}" /></span></c:otherwise>
                            </c:choose>
                        </td>
                        <td><fmt:formatDate value="${product.createdAt}" pattern="yyyy-MM-dd HH:mm" /></td>
                        <td>
                            <a href="javascript:void(0);" onclick="confirmDelete(${product.id})" class="btn-danger">删除</a>
                        </td>
                    </tr>
                </c:forEach>
                <c:if test="${empty products}">
                    <tr>
                        <td colspan="8" style="text-align: center;">系统中没有商品。</td>
                    </tr>
                </c:if>
                </tbody>
            </table>
        </div>
    </main>
</div>

</body>
</html> 